package com.ysm.smfu.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.widget.ImageView;
import android.widget.TextView;

import com.ysm.smfu.R;
import com.ysm.smfu.utils.MyImageBitmapUtil;
import com.zhy.autolayout.AutoLinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/10/11.
 */
public class ConsumerActivity extends Activity {
    @BindView(R.id.consumer_qr)
    ImageView consumerQr;
    @BindView(R.id.saveToLoc)
    AutoLinearLayout saveToLoc;
    @BindView(R.id.consumer_setcount)
    TextView consumerSetcount;
    private Bitmap bitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_consumer_qr);
        ButterKnife.bind(this);
//        获取二维码
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.qr_img);
        consumerQr.setImageBitmap(bitmap);

    }

    @OnClick(R.id.saveToLoc)
    public void onClick() {
        saveToLoc();
    }

    /**
     * 保存到本地
     */
    private void saveToLoc() {
        MyImageBitmapUtil.saveQrToLoc(this, bitmap);
    }

    private void showDialog() {
        AlertDialog dialog = new AlertDialog.Builder(this)
                .setTitle("是否打开本地相册")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        openAlbum();
                    }
                })
                .setNegativeButton("取消", null)
                .create();

        dialog.show();
    }

    /**
     * 打开相册
     */
    // 打开本地相册
    public void openAlbum() {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);
        startActivity(intent);
    }
}
